package com.example.dockerdemo;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @PACKAGE_NAME: com.example.dockerdemo
 * @NAME: Colon
 * @description:lambda表达式测试以及简写模式::
 * @DATE: 2024/4/17
 * @USER: fz
 **/
public class Colon{

    // TODO::使用时，参数传递有点奇怪
    @Test
    public void test(){
        String[] arr = { "Barbara", "James", "Mary", "John",
                "Patricia", "Robert", "Michael", "Linda" };
        //引用String类型的任意对象的compareToIgnoreCase方法实现忽略大小写排序
        Arrays.sort(arr, String::compareToIgnoreCase);
        //上一行等价于
        //Arrays.sort(arr, (a,b)->a.compareToIgnoreCase(b));
        //用匿名内部类实现忽略大小写排序
        //Arrays.sort(arr, new Comparator<String>() {
        //    @Override
        //    public int compare(String o1, String o2) {
        //        return o1.compareToIgnoreCase(o2);
        //    }
        //);
        for(String s:arr){
            System.out.println(s);
        }
    }
    @Test
    public void test2(){
        List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 23, "male", "New York"));
        personList.add(new Person("Jack", 7000, 25, "male", "Washington"));
        personList.add(new Person("Lily", 7800, 21, "female", "Washington"));
        personList.add(new Person("Anni", 8200, 24, "female", "New York"));
        personList.add(new Person("Owen", 9500, 25, "male", "New York"));
        personList.add(new Person("Alisa", 7900, 26, "female", "New York"));

        List<String> fiterList = personList.stream().filter(x -> x.getSalary() > 8000).map(Person::getName)
                .collect(Collectors.toList());
        //System.out.println("高于8000的员工姓名：" + fiterList);

        // stream流遍历
        //personList.stream().forEach(System.out::println);
        // 遍历输出姓名
        //personList.stream().map(Person::getName).forEach(System.out::println);
        // 遍历输出姓名和年龄
        personList.stream().map(person -> person.getName() + ":" + person.getAge()).forEach(System.out::println);


        String a = "hhh";
        String intern = a.intern();
    }
}
